package com.springdemo;

import com.springdemo.bean.Product;
import com.springdemo.bean.Student;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class MainApp {
    public static void main(String[] args) {
        // 加载Spring配置文件，初始化IOC容器
        ApplicationContext context = new ClassPathXmlApplicationContext("applicationContext.xml");

        System.out.println("Spring IOC容器初始化完成！");

        // 从容器中获取Product对象
        Product product = (Product) context.getBean("product");
        System.out.println("获取到的Product对象：" + product);

        // 从容器中获取Student对象
        Student student1 = (Student) context.getBean("student1");
        System.out.println("获取到的第一个Student对象：" + student1);

        // 另一种获取Bean的方式：指定类型
        Student student2 = context.getBean("student2", Student.class);
        System.out.println("获取到的第二个Student对象：" + student2);
    }
}
